﻿#include "EditorTestButtonStatusView.h"
#include "EditorTestButtonStatusViewModel.h"
#include "Widgets/ButtonWidget.h"
#include "Widgets/Positioners/HorizontalPositionerWidget.h"

#include "Framework/Editor.h"
#include "Theme/EditorTheme.h"


void REditorTestButtonStatusView::BindViewModel(TSharedObjectPtr<REditorStatusItemViewModel> InViewModel)
{
    Super::BindViewModel(InViewModel);
    TestButtonViewModel=InViewModel;
}

void REditorTestButtonStatusView::FillWidgets(TSharedObjectPtr<RHorizontalPositionerWidget> InLeftPart, TSharedObjectPtr<RHorizontalPositionerWidget> InRightPart)
{
    Super::FillWidgets(InLeftPart, InRightPart);
    
    //添加一个按钮
    auto ButtonWidget = NewWidget<RButtonWidget>(InRightPart);
    ButtonWidget->Width=50;
    ButtonWidget->Anchor.VerticalFill(InRightPart);
    ButtonWidget->Text=U"测试";
    ButtonWidget->OnClicked.BindLambda([this](const SMouseButtonEvent&)
    {
        TestButtonViewModel->Test();
        return true;
    });
    RButtonWidgetWeakPtr WeakButton=ButtonWidget;
    ButtonWidget->BackgroundStyle.FillColor=[WeakButton](){
        if(WeakButton->IsHovered())
        {
            return REditor::Get()->CurrentTheme->ForegroundColor;
        }
        return SColor::None;
    };
}
